<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>菜单/角色管理</h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>
            首页</a></li>
        <li><a href="#">系统管理</a></li>
        <li class="active">菜单/角色管理</li>
    </ol>
</section>


<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box box-primary">
                <div class="box-body">
                    <div class="row">
                        <div class="col-sm-3">
                            <div class="dataTables_length">
                                <label>
                                    <select class="form-control input-sm page" style="width:auto;">
                                        <option>10</option>
                                        <option>20</option>
                                        <option>30</option>
                                        <option>30</option>
                                        <option>40</option>
                                    </select>
                                    记录/页
                                </label>
                            </div>
                        </div>
                        <div class="col-sm-9">
                            <div class="dataTables_filter" id="searchDiv">
                                <input type="search" placeholder="请输入角色名称" title="角色名称" name="name"
                                       class="form-control">
                                <div class="btn-group" style="margin-bottom:2px;">
                                    <button type="button" class="btn btn-primary" data-btn-type="search">查询</button>
                                </div>
                                <div class="btn-group" style="margin-bottom:2px;">
                                    <button type="button" class="btn btn-default" data-btn-type="add">新增</button>
                                </div>
                            </div>
                        </div>
                    </div>


                    <table id="check_table" class="table table-bordered table-striped table-hover" style="margin-bottom:20px;">
                        <thead>
                        <tr>
                            <th name="id" style="display:none;">id</th>
                            <th name="name" style='text-align: center;'>用户名</th>
                            <th name="remark" style='text-align: center;'>描述</th>
                            <th name="" style='text-align: center;'>功能选项</th>
                        </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                    <div class="paging"></div>
                </div>
            </div>
        </div>
        </div>
    </div>
</section>

<script>

    $(function() {
        var menutree;
        var table=initTable("/root/role/num","/root/role",
            $(".content #searchDiv"),
            $(".content table"),
            $(".content .page"),
            $(".content .paging"),
            "fa fa-share","菜单");
        var param={
            addHtmlUrl:"./function/roleAdd.html",
            updateHtmlUrl:"./function/roleEdit.html",
            getEntityUrl:"/root/role",
            deleteEntityUrl:"/root/role",
            addEntityUrl:"/root/role",
            updateEntityUrl:"/root/role/assignRoleFunction",
            table:$("table"),
            addButton:$("[data-btn-type='add']"),
            addTitle:"添加角色",
            editTitle:"角色权限分配",
            getEntityBefore:function () {
                menutree = $('#menutree').jstree({
                    'core':{
                        'data' : {
                            'url' : '/root/function/tree/map'
                        }
                    },
                    'plugins':['checkbox']
                });
            },
            initFormDataCallback:function (value) {
                setTimeout(function () {
                    menutree.jstree('deselect_all');
                    $.each(value, function (index, item) {
                        menutree.jstree('select_node', item)
                    });
                    menutree.jstree('close_all');
                }, 200)
            },
            updateBeforeCallback:function (value) {
                console.log(value);
                var ids = menutree.jstree('get_selected',false);
                console.log(ids);
                $('.jstree-undetermined').each(function(index,item){
                    ids.push($(this).parents('.jstree-node').attr('id'));
                });
                ids = ids.join(',');
                console.log({bhs:ids,roleId:value.id});
                return {bhs:ids,roleId:value.id};
            }
        };
        var winId=EditEntity(param,table.search);
    });

</script>
